package com.liu.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.liu.mapper.UserInfoMapper;
import com.liu.po.UserInfo;
import com.liu.service.UserInfoService;

@Service
public class UserInfoServiceImpl implements UserInfoService {

	@Resource(name = "userInfoMapper")
	private UserInfoMapper userInfoMapper;

	@Override
	public boolean addUser(UserInfo user) {

		int count = userInfoMapper.addUser(user);

		if (count > 0) {
			return true;
		}

		return false;
	}

	public void setUserInfoMapper(UserInfoMapper userInfoMapper) {
		this.userInfoMapper = userInfoMapper;
	}

	@Override
	public List<UserInfo> getUserList(UserInfo user) {

		if (user != null && user.getUserName() != null
				&& !user.getUserName().equals("")) {

			user.setUserName("%" + user.getUserName() + "%");
		}

		return userInfoMapper.getUserList(user);
	}

	@Override
	public boolean updateUser(UserInfo user) {
		int count = userInfoMapper.updateUser(user);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@Override
	public UserInfo getUser(Integer userId) {

		if (userId != null) {

			return userInfoMapper.getUser(userId);
		}

		return null;
	}

	@Override
	public boolean deleteUser(Integer userId) {
		int count = userInfoMapper.deleteUser(userId);
		if (count > 0) {
			return true;
		}

		return false;
	}

}
